package oj;

import java.util.ArrayList;
import java.util.List;

public class LC17 {
    String[] letter_map = {" ","*","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
    public List<String> letterCombinations(String digits) {
        List<String> list=new ArrayList<>();
        if(digits==null || digits.length()==0) return list;

        func(list,digits,new StringBuilder(),0);
        return list;

    }
    public void func(List<String> list,String digits,StringBuilder res,int index){
        if(index==digits.length()){
            list.add(res.toString());
            return;
        }

        char ch=digits.charAt(index);
        String str=letter_map[ch-'0'];

        int len=str.length();
        for(int i=0;i<len;i++){
            res.append(str.charAt(i));
            func(list,digits,res,index+1);
            res.deleteCharAt(res.length()-1);
        }
    }
}
